//#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,avx2")
#pragma GCC optimize("Ofast","unroll-loops","inline")
#include<bits/stdc++.h>
#define ll long long
#define int ll
#define pb push_back
#define pii pair<int,int>
#define fi first
#define se second
#define MP make_pair
using namespace std;
const int N=4e5+10,M=1e6+10,mod=998244353;
int T,b[N],ct,a[N];
struct data{int s,c;__int128 f,g;};
inline data operator +(data x,data y){
	data z;z.c=x.c+y.c;
	z.s=x.s+y.s;
	z.f=x.f+y.f+(__int128)x.s*y.c;
	z.g=x.g+y.g+(__int128)x.c*y.s;
	return z;
}
struct Seg{
	data t[N<<2];
	inline void ph(int rt){t[rt]=t[rt<<1]+t[rt<<1|1];}
	inline void upd(int rt,int l,int r,int p){
		if(l==r){
			if(t[rt].c) t[rt].c=t[rt].s=0,t[rt].f=t[rt].g=0;
			else t[rt].c=1,t[rt].s=b[l],t[rt].f=t[rt].g=b[l];
			return ;
		}
		int mid=(l+r)>>1;
		if(p<=mid) upd(rt<<1,l,mid,p);
		else upd(rt<<1|1,mid+1,r,p);
		ph(rt);
	}
	inline int qL(int rt,int l,int r,int k){
		if(!k) return 0;
		if(k==t[rt].c) return t[rt].s;
		if(l==r) return t[rt].s;
		int mid=(l+r)>>1;
		if(t[rt<<1].c<k) return t[rt<<1].s+qL(rt<<1|1,mid+1,r,k-t[rt<<1].c);
		else return qL(rt<<1,l,mid,k);
	}
	inline int qR(int rt,int l,int r,int k){
		if(!k) return 0;
		if(k==t[rt].c) return t[rt].s;
		if(l==r) return t[rt].s;
		int mid=(l+r)>>1;
		if(t[rt<<1|1].c<k) return t[rt<<1|1].s+qR(rt<<1,l,mid,k-t[rt<<1|1].c);
		else return qR(rt<<1|1,mid+1,r,k);
	}
	inline data qF(int rt,int l,int r,int k){
		if(k==t[rt].c) return t[rt];
		if(l==r) return t[rt];
		int mid=(l+r)>>1;
		if(t[rt<<1].c<k) return t[rt<<1]+qF(rt<<1|1,mid+1,r,k-t[rt<<1].c);
		else return qF(rt<<1,l,mid,k);
	}
	inline data qG(int rt,int l,int r,int k){
		if(k==t[rt].c) return t[rt];
		if(l==r) return t[rt];
		int mid=(l+r)>>1;
		if(t[rt<<1|1].c<k) return qG(rt<<1,l,mid,k-t[rt<<1|1].c)+t[rt<<1|1];
		else return qG(rt<<1|1,mid+1,r,k);
	}
}t;
signed main(){
	freopen("kte.in","r",stdin);
	freopen("kte.out","w",stdout);
	ios::sync_with_stdio(false);cin.tie(0);cout.tie(0);
	cin>>T;
	for(int i=1;i<=T;i++) cin>>a[i],b[i]=a[i];
	ct=T;
	sort(b+1,b+T+1);ct=unique(b+1,b+T+1)-b-1;
	for(int i=1;i<=T;i++) a[i]=lower_bound(b+1,b+ct+1,a[i])-b;
	for(int _=1,x;_<=T;_++){
		x=a[_];
		t.upd(1,1,ct,x);
		int ans=0,n=t.t[1].c;
		int l=2,r=(n+1)/2,p1=(n+1)/2+1,p2=(n+1)/2;
		while(l<=r){
			int mid=(l+r)>>1;
			if(t.qL(1,1,ct,mid)<=t.qR(1,1,ct,mid-1)) r=mid-1,p1=mid;
			else l=mid+1;
		}
		--p1;
		l=(n+1)/2+1,r=n;
		while(l<=r){
			int mid=(l+r)>>1;
			if(t.qL(1,1,ct,mid)<=t.qR(1,1,ct,mid-1)) l=mid+1,p2=mid;
			else r=mid-1;
		}
		ans=t.qR(1,1,ct,p2)-t.qL(1,1,ct,p1);
		__int128 res=t.qG(1,1,ct,ct).g-t.qF(1,1,ct,ct).f;
		res-=t.qG(1,1,ct,p2).g-t.qF(1,1,ct,p2).f;
		ans+=res;
		if(p1>1) ans+=t.qG(1,1,ct,p1-1).g-t.qF(1,1,ct,p1-1).f;
		cout<<ans<<'\n';
	}
	return 0;
}
